# -*- coding:utf8 -*- #
# -----------------------------------------------------------------------------------
# ProjectName:  smart-meter-iot-test-console
# FileName:     getDeviceSecret.py
# Author  :     
# Datetime:     2023/4/7 23:46
# Description： 获取设备密钥，该设备在物联网平台上的身份证书信息之一。
# -----------------------------------------------------------------------------------
import calendar
import time

from common.util.configUtil.configUtil import ConfigUtil
from common.util.logUtil.logUtil import LoggerUtil
from common.util.requestsUtil.requestsUtil import RequestsUtil
from common.util.timeUtil.timeUtil import get_timestamp
from core.mqtt.libProject.getSign.getSign import get_sign

req = RequestsUtil()
conf = ConfigUtil()
logger = LoggerUtil()


def get_device_secret(deviceName: str):
    productKey = conf.get_productkey()
    timestamp = get_timestamp()
    sign = get_sign(deviceName, timestamp)
    url = conf.get_mqtt_url()
    params = {"productKey": productKey, "deviceName": deviceName, "sign": sign, "timestamp": timestamp}
    try:
        return req.send_request("get", url, params=params), url.split("?")[0]
    except Exception as jsonError:
        logger.error(jsonError)
        return False


if __name__ == '__main__':
    print(get_device_secret("V10230190000"))
